package com.anne.fish.webapp.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.anne.fish.Constants;
import com.anne.fish.model.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MemberLoginInterceptor extends AbstractInterceptor {

	private String signin;

	public String getSignin() {
		return signin;
	}

	public void setSignin(String signin) {
		this.signin = signin;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	 
	public String intercept(ActionInvocation invocation) throws Exception {

		HttpServletRequest request = ServletActionContext.getRequest();

		HttpSession session = request.getSession(true);
		// 没有登录

		User rser = (User) session.getAttribute(Constants.USER ); 
		if (rser == null) {

			String path = request.getRequestURI();
			String query = request.getQueryString();
			if (query != null) {
				path += "?" + query;
			}
			session.setAttribute(Constants.FORWARD, path);
			return signin;
		}

		return invocation.invoke();
	}

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void init() {
		// TODO Auto-generated method stub

	}
}